package com.xiaoshuaila.workbench.service;

import com.xiaoshuaila.settings.dao.userdao;
import com.xiaoshuaila.settings.domain.user;
import com.xiaoshuaila.tool.*;
import com.xiaoshuaila.vo.Activityvo1;
import com.xiaoshuaila.workbench.dao.Activitydao;
import com.xiaoshuaila.workbench.dao.Activitydaoremark;
import com.xiaoshuaila.workbench.domain.Activity;
import com.xiaoshuaila.workbench.domain.Activityremark;
import com.xiaoshuaila.vo.Activityvo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActivityserviceImpl implements Activityservice {
    private Activitydao activitydao=
            SqlSessionUtil.getSqlSession().getMapper(Activitydao.class);
    private userdao userdao=
            SqlSessionUtil.getSqlSession().getMapper(userdao.class);
    private Activitydaoremark activitydaoremark=
            SqlSessionUtil.getSqlSession().getMapper(Activitydaoremark.class);
    @Override
    public List<Activity> findall() {
        return activitydao.selectall();
    }

    @Override
    public List<user> findalluser() {
        return userdao.selectall();
    }

    @Override
    public boolean delect(String[] id) {
        boolean isok=true;
        int count1=activitydao.selectremark(id);
        int count2=activitydao.delectremark(id);
        if (count1!=count2)
            isok=false;
        int count3=activitydao.delect(id);
        if (count3!=id.length)
            isok=false;
        return isok;
    }

    @Override
    public int delectremark(String[] id) {
        return activitydao.delectremark(id);
    }

    @Override
    public int findremark(String[] id) {
        return activitydao.selectremark(id);
    }

    @Override
    public Map update(String id) {
        List<user>list=userdao.selectall();
        Activity activity=activitydao.update(id);
        Map map=new HashMap();
        map.put("user",list);
        map.put("activity",activity);
        System.out.println(activity);
        return map;
    }

    @Override
    public int update1(Activity activity) {
        return activitydao.update1(activity);
    }

    @Override
    public Activity datail(String id) {

        return activitydao.datail(id);
    }

    @Override
    public int save(Activity activity) {
        int i=activitydao.insert(activity);
        return i;
    }

    @Override
    public Map pagelist(Map serch) {
        List<Activityvo>list=activitydao.pagelist(serch);
        serch.put("pageNo",null);
        serch.put("pageSize",null);
        List<Activityvo>list1=activitydao.pagelist(serch);
        System.out.println(list1.size());
        Map map=new HashMap();
        map.put("total",list1.size());
        map.put("list",list);
        for (Activityvo a:list
        ) {
            System.out.println(a);
        }
        return map;
    }

    @Override
    public List<Activityremark> selectrmark(String id) {
        return activitydaoremark.selectall(id);
    }

    @Override
    public int deleteremark(String id) {
        return activitydaoremark.deleteremark(id);
    }

    @Override
    public int insertremark(Activityremark activityremark) {
        return activitydaoremark.insert(activityremark);
    }

    @Override
    public int updateremark(Activityremark activityremark) {
        return activitydaoremark.update(activityremark);
    }

    @Override
    public List<Activityvo1> findactivity(String id) {
        return activitydao.findactivity(id);
    }

    @Override
    public List<Activity> findactivitybyname(Map map) {
        return activitydao.finfactivitybyname(map);
    }

    @Override
    public List<Activity> findactivityname(String name) {
        return activitydao.finfactivityname(name);
    }
}
